package com.ruoyi.product.controller;


import com.ruoyi.product.Service.ProductService;
import com.ruoyi.product.pojo.Product;
import com.ruoyi.product.pojo.Resuit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("Product")
@Api(value = "接口文档",tags = "贷款-Api")
@Slf4j
public class ProductController {


	@Resource
	ProductService productService;


	/**
	 * 查看贷款产品
	 * @param product
	 * @return
	 */
	@PostMapping("selectByProduct")
	@ApiOperation("查询接口")
	private Resuit selectByProduct(@RequestBody Product product){
		List<Product> productList =productService.selectByProduct(product);
		log.info("这是查询接口");
		return  new Resuit(200,"查找成功",productList);
	}

	/**
	 * 修改贷款产品信息
	 * @param product
	 * @return
	 */
	@PostMapping ("updateById")
	@ApiOperation("修改接口")
	private  Resuit updateById(@RequestBody Product product){
		try {
			productService.updateById(product);
			return  new Resuit(200,"修改成功",null);
		}catch (Exception e){
			e.getMessage();
		}
			return  new Resuit(250,"修改失败",null);
	}

	@PostMapping("insertProduct")
	@ApiOperation("新增接口")
	private  Resuit insertProduct(@RequestBody Product product){
				productService.insertProduct(product);
			return  new Resuit(200,"添加成功",null);
	}


	@PostMapping("deleteById/{pid}")
	@ApiOperation("删除接口")
	public  Resuit deleteById(@PathVariable("pid")long pid){
		productService.deleteById(pid);
		return  new Resuit(200,"删除成功",null);
	}


	/**
	 * 查询代办任务
	 * @param uid
	 * @return
	 */
	@RequestMapping("queryTask/{uid}")

	public  Resuit queryTask(@PathVariable("uid")Integer uid){
	 return 	productService.queryTask(uid);
	}

	/**
	 * 完成个人任务
	 * @param pid
	 * @return
	 */
	@RequestMapping("fulfilaTask/{pid}")
	public  Resuit fulfilaTask(@PathVariable("pid")Integer pid){
			return  productService.fulfilaTask(pid);
	}

}
